package com.hjm.project.terminal.pos.controller;

import java.util.List;
import java.util.Map;

import com.hjm.framework.config.CustomConfig;
import com.hjm.project.clientImg.clientImg.domain.ClientImg;
import com.hjm.project.clientImg.clientImg.service.IClientImgService;
import com.hjm.project.terminal.pos.domain.AgentApplyPos;
import com.hjm.project.terminal.pos.service.IAgentApplyPosService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 服务商划拨、撤销机具申请信息Controller
 * 
 * @author LOVE
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/terminal/pos")
public class AgentApplyPosController extends BaseController
{
    private String prefix = "terminal/pos";

    @Autowired
    private IAgentApplyPosService agentApplyPosService;

    @Autowired
    private IClientImgService clientImgService;

    @RequiresPermissions("terminal:pos:view")
    @GetMapping()
    public String pos()
    {
        return prefix + "/pos";
    }

    /**
     * 查询服务商划拨、撤销机具申请信息列表
     */
    @RequiresPermissions("terminal:pos:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentApplyPos agentApplyPos)
    {
        startPage();
        List<AgentApplyPos> list = agentApplyPosService.selectAgentApplyPosList(agentApplyPos);
        return getDataTable(list);
    }

    /**
     * 导出服务商划拨、撤销机具申请信息列表
     */
    @RequiresPermissions("terminal:pos:export")
    @Log(title = "服务商划拨、撤销机具申请信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentApplyPos agentApplyPos)
    {
        List<AgentApplyPos> list = agentApplyPosService.selectAgentApplyPosList(agentApplyPos);
        ExcelUtil<AgentApplyPos> util = new ExcelUtil<AgentApplyPos>(AgentApplyPos.class);
        return util.exportExcel(list, "pos");
    }

    /**
     * 新增服务商划拨、撤销机具申请信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务商划拨、撤销机具申请信息
     */
    @RequiresPermissions("terminal:pos:add")
    @Log(title = "服务商划拨、撤销机具申请信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MultipartFile payPic, AgentApplyPos agentApplyPos)
    {
        Map<String,String> map=agentApplyPosService.insertAgentApplyPos(payPic,agentApplyPos);
        if ("00".equals(map.get("code"))){
            return AjaxResult.success();
        }else{
            return AjaxResult.warn(map.get("msg"));
        }
    }

    /**
     * 修改服务商划拨、撤销机具申请信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AgentApplyPos agentApplyPos = agentApplyPosService.selectAgentApplyPosById(id);
        mmap.put("agentApplyPos", agentApplyPos);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务商划拨、撤销机具申请信息
     */
    @RequiresPermissions("terminal:pos:edit")
    @Log(title = "服务商划拨、撤销机具申请信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentApplyPos agentApplyPos)
    {
        return toAjax(agentApplyPosService.updateAgentApplyPos(agentApplyPos));
    }

    /**
     * 删除服务商划拨、撤销机具申请信息
     */
    @RequiresPermissions("terminal:pos:remove")
    @Log(title = "作废服务商划拨、撤销机具申请信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        AgentApplyPos agentApplyPos=new AgentApplyPos();
        agentApplyPos.setId(Long.valueOf(ids));
        agentApplyPos.setHandleRs("2");
        return toAjax(agentApplyPosService.updateAgentApplyPos(agentApplyPos));
    }

    /**
     * 选择服务商
     */
    @GetMapping("/selectAgentInfo")
    public String selectAgentInfo(ModelMap map)
    {
        return "agentInfo/agentInfo/selectAgentInfo";
    }


    /**
     * 选择服务商(所有)
     */
    @GetMapping("/selectAgentInfoAll")
    public String selectAgentInfoAll(ModelMap map)
    {
        return "agentInfo/agentInfo/selectAgentInfoAll";
    }

    /**
     * 财务审核页面
     */
    @RequiresPermissions("terminal:pos:financeApplyList")
    @GetMapping("/financeApplyList")
    public String financeApplyList(ModelMap map)
    {
        return prefix+"/financeApplyList";
    }

    /**
     * 查询服务商划拨、撤销机具申请信息列表
     */
    @PostMapping("/FList")
    @ResponseBody
    public TableDataInfo FList(AgentApplyPos agentApplyPos)
    {
        startPage();
        List<AgentApplyPos> FList = agentApplyPosService.selectAgentApplyPosFList(agentApplyPos);
        return getDataTable(FList);
    }

    /**
     * 终端划拨审核
     */
    @Log(title = "终端划拨审核", businessType = BusinessType.OTHER)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(@RequestParam Map<String, Object> map)
    {
        AgentApplyPos agentApplyPos=new AgentApplyPos();
        agentApplyPos.setId(Long.valueOf(map.get("id").toString()));
        agentApplyPos.setFinanceStatus(map.get("financeStatus").toString());
        return toAjax(agentApplyPosService.updateAgentApplyPos(agentApplyPos));
    }

    @GetMapping("/lookPayImg/{orderNum}")
    public String lookPayImg(@PathVariable("orderNum")String orderNum, ModelMap mmap)
    {
        ClientImg clientImg=new ClientImg();
        clientImg.setClientno(orderNum);
        clientImg.setType(Long.valueOf("46"));
        List<ClientImg> clientImgs = clientImgService.selectclientImgList(clientImg);
        mmap.put("orderNum", orderNum);
        mmap.put("clientImgs", clientImgs);
        mmap.put("imgUrl", CustomConfig.getImgUrl());
        return prefix+"/lookPayImg";
    }

    /**
     * 撤机申请
     */
    @GetMapping("/revoke")
    public String revoke(ModelMap map)
    {
        return prefix + "/revoke";
    }

}
